<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>       
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="${_resources}/logo.png"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">                                            
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />  
<title>修改样式模板</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<script type="text/javascript">
//表单提交方法
function formSubmit(){
	tipPostion();
	if($("#textfield").val() == ''){
		layer.msg("请先选择上传文件");
		return;
	}
	if(judgeFileType()){
		var loadDiv = window.parent.layer.load(1,{shade: [0.3, '#ccc']}); //换了种风格
		var options = {
				dataType:"text",
				success:function(json){
					window.parent.layer.close(loadDiv);
					$("#submit").attr("onclick","");
					layer.msg(json,{shift:2,time:2000},function(){
					parent.closeWin();
					});
				},
				error:function(json){
					layer.msg("系统错误,请联系管理员");
					window.parent.layer.close(loadDiv);
				}
			};
			 $('#form').ajaxSubmit(options);
	}
}
//验证必填提示显示位置
function tipPostion(){
	$("#form").validationEngine({
		autoHidePrompt:true,//自动隐藏
		autoHideDelay:2000,
		showOnMouseOver:true,//当鼠标移出时触发
		promptPosition:'bottomLeft',//提示信息的位置
		inlineValidation: true,//是否即时验证，false为提交表单时验证,默认true  
	});
}
//取消和关闭调用的方法
function cancelAndClose(){
	parent.closeWin();
}

function judgeFileType(){
	var fileType =$("#textfield").val();
	if(fileType == ''){
		return false;
	}else{
		var typeMark =  fileType.substring(fileType.length-4,fileType.length);
		if( typeMark == ".doc"||typeMark ==".DOC"||(typeMark =="docx" &&fileType.indexOf("."))||(typeMark=="DOCX"&&fileType.indexOf("."))){
			return true;
		}else{
			parent.layer.msg("请选择doc,docx格式文件!");
			return false;
		}	
	}
}
function judgeName(){
	var path="${_baseUrl}/KmStyleDocumentTemplateController/verifyName";
	var name = $("#documentTemplateName").val();
	if(name !=""){
		$.ajax({    
			type: "POST",    
			async: false,    
			url:path,
			data:{
				"styleName":name
			},
			dataType:"json",    
			success: function (json) {   
				if(json.code=="2"){
					layer.msg("模板名称已经存在");
					$("#documentTemplateName").val("");
				}
			}   
		});
	}
}

</script>
<style>
	.important_Preservation{margin-top:0px;}
</style>
</head>
<body>
<form name="testFileFileUpload" id="form" action ="${_baseUrl}/KmStyleDocumentTemplateController/modifyStyleTemplate" method="post"  enctype="multipart/form-data" > 	
<input type="hidden" name="token" value="${token}" />
<input type="hidden" name="id" value="${id}">
 <div style="overflow: auto; width:98%;margin: auto;height:160px">
	<table class="table table-bordered table_inline" >
    <tbody >
    <tr>
        <td height="50" width="15%" align="center"><span style="color: #f00">*</span>样式模板名称</td>
        <td width="35%" valign="middle">
            <div class="">
                <input type="text" class="nav_input validate[required,funcCall[judgeName]" name="styleDocumentName" id="styleDocumentName" value="${styleDocumentName}" disabled="disabled" placeholder="请输入">
            </div>
        </td>
    </tr>
    <tr>
        <td width="15%" valign="middle" align="center"><span style="color: #f00">*</span>新模板</td>
        <td width="35%">
			<div class="upload" style="position: relative;">
			      <input class="upload_input" type="file" class="validate[required,funcCall[judgeFileType]" name=multipartfile id="textfield" >
			      <div class="upload_text"></div>
			      <div class="upload_text_a"></div>
			      <a class="upload_btn" href="javascript:;">上传</a>
			      <a class="upload_delete" href="javascript:;"></a>
			  </div>
		</td>
    </tr>
    </tbody>
</table>
</div>
<div class="important_Preservation">
    <shiro:hasPermission name="KmStyleDocumentTemplateController:modifyStyleTemplate1">
         <a href="javascript:;" id="submit" onclick="formSubmit();">提交</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="KmStyleDocumentTemplateController:close1">
        <a href="javascript:;" id="cancel" onclick = "cancelAndClose();">取消</a>
    </shiro:hasPermission>
</div>
</form>
</body>
<script type="text/javascript">
$(function(){
	$("input[type='file']").change( function() {
		var fileType =$("#textfield").val();
		$(".upload_text").text(fileType);
		$(".upload_text").attr("title",fileType);
		$(".upload_delete").click(function(){
			$(".upload_text").val("");
			$(".upload_text").text("");
			$("#textfield").val("");
			$(".upload_text").attr("title","");
			$("#testBasedDocumentName").val("");
			});
		});
	})
</script>
</html>